package example.demo.controller;

import example.demo.bean.User;
import example.demo.vo.ResultVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
//对本类中的方法开启参数验证功能
@Validated
public class ValidatorController {

    /*
     *{
     * "birthday": "2020-10-10 22:22:22",
     * "email": "12347@qq.com",
     * "localDateTime": "2020-10-10 22:22:22",
     * "password": "123kk",
     * "username": "懒羊羊"
     *}
     *
     */
    @RequestMapping(path = "/addUserHaveValid"/*, method = RequestMethod.POST*/)
    public ResultVO addUserHaveValid(@RequestBody @Valid User user) {
        return ResultVO.success(user);
    }

    @RequestMapping(path = "/addUserNoValid"/*, method = RequestMethod.POST*/)
    public ResultVO addUserNoValid(@RequestBody @Valid User user) {
        return ResultVO.success(user);
    }
}
